/*
 * @Author: wangming
 * @Date: 2022-06-01 16:28:26
 * @LastEditors: wangming
 * @LastEditTime: 2022-06-01 16:45:38
 * @FilePath: /hanma-application-designer-fed/src/components/DesignPreview/index.js
 * @Description: 
 */

import Vue from 'vue';
import template from './template';
import store from '@/store'
import router from '@/router';
import i18n from '@/i18n'
router.afterEach(async () => {
  CreateInstance.clearVm()
});
const ModalTemplate = {
  store,
  router,
  i18n,
  methods: {
    async openDrawer(...arg) {
      this.$refs._component.openDrawer(...arg)
    },
  },
  render(h) {
    return h(template, {
      ref: '_component'
    })
  }
}
class CreateInstance {
  static instance = null;
  static openDrawer(...arg) {
    this.create()
    this.instance.openDrawer(...arg)
  }
  static clearVm() {
    if (this.instance) {
      this.instance.$el.remove()
      this.instance.$destroy()
      this.instance = null
    }
  }
  static create() {
    if (!!this.instance) {
      return this.instance
    } else {
      let dialogDiv = document.createElement('div')
      document.body.appendChild(dialogDiv)
      this.instance = new Vue(ModalTemplate).$mount(dialogDiv)
    }
  }

}
export default CreateInstance;
